<?php
namespace addons\Dailywords;

use app\common\controller\Addons;

class Dailywords extends Addons
{
    public $info = [
        'name'=>'Dailywords',
        'title'=>'随机一言',
        'description'=>'Mortal Admin示例插件',
        'status'=>1,
        'author'=>'Mortal Admin',
        'version'=>'0.1'
    ];
    public function install(){
        return true;
    }
    public function uninstall(){
        return true;
    }
    public function update(){
        return true;
    }
    public function adminWelcome($param) {
        $config = db('addons')->where('name',$this->info['name'])->find();
        $_config = !empty($config['config']) ? json_decode($config['config'],true) : ['api_url'=>'https://api.52vmy.cn/api/wl/yan/yiyan'];
        $info = file_get_contents($_config['api_url']);
        $info = json_decode($info,true);
        if($info&&isset($info['code'])&&$info['code']==200){
            if(isset($info['data'])&&!empty($info['data'])){
                if($info['data']['hitokoto']&&$info['data']['author']){
                    $str = '<div class="layui-card">';
                    $str .= '<div class="layui-card-header">';
                    $str .= $info['data']['author'];
                    $str .= '</div>';
                    $str .= '<div class="layui-card-body" style="line-height:40px;">';
                    $str .= $info['data']['hitokoto'];
                    $str .= '</div>';
                    echo $str;
                }
            }
        }
    }
}